//
//  AuthenPendingCheckingCell.swift
//  kxf
//
//  Created by Mac on 2024/3/12.
//

import Foundation
import UIKit

class AuthenPendingCheckingCell: UITableViewCell {
    
    var queryBlock:(()->())?
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.backgroundColor = .COLOR_LIGHT_GREY
        self.selectionStyle = .none
        initUI()
    }
    lazy var whiteView : UIView = {
        let vi = UIView()
        vi.layer.cornerRadius = kFitWidth(20)
        vi.clipsToBounds = true
        vi.backgroundColor = .white
        vi.isUserInteractionEnabled = true
        
        return vi
    }()
    lazy var mercPhoneLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 16, weight: .regular)
        lab.adjustsFontSizeToFitWidth = true
//        lab.text = "联系商家 14343423423"
        
        return lab
    }()
    lazy var queryButton : UIButton = {
        let btn = UIButton()
        btn.setTitle("查询状态", for: .normal)
        btn.setTitleColor(.THEME, for: .normal)
        btn.titleLabel?.font = .systemFont(ofSize: 14, weight: .medium)
        
        btn.addTarget(self, action: #selector(queryAction), for: .touchUpInside)
        
        return btn
    }()
    lazy var arrowImgView : UIImageView = {
        let img = UIImageView()
        img.setImgLocal(imgName: "login_arrow_img")
        return img
    }()
    lazy var timeLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK666
        lab.font = .systemFont(ofSize: 14)
//        lab.text = "2024-03-11 21:55:21"
        
        return lab
    }()
    
    lazy var statusLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .THEME
        lab.font = .systemFont(ofSize: 14, weight: .medium)
        lab.text = "正在审核"
//        lab.isHidden = true
        
        return lab
    }()
    lazy var lineView : UIView = {
        let vi = UIView()
        vi.backgroundColor = .COLOR_LIGHT_GREY
        
        return vi
    }()
    lazy var phoneLabel : UILabel = {
        let lab = UILabel()
        lab.textColor = .COLOR_TEXT_BLACK999
        lab.font = .systemFont(ofSize: 12)
//        lab.text = "1433334349（小微）"
        
        return lab
    }()
    
}

extension AuthenPendingCheckingCell{
    func updateUI(dict:NSDictionary) {
        mercPhoneLabel.text = "联系商家 \(dict["phone"]as? String ?? "")"
        timeLabel.text = "\(Date().timestampToDate(timestamp: TimeInterval((dict["createTime"]as? Int ?? 0)/1000)))"
        
        var merchantType = "小微"
        ////0   企业   1  小微   2 个体
        if dict["mchType"]as? String ?? "" == "0"{
            merchantType = "企业"
        }else if dict["mchType"]as? String ?? "" == "2"{
            merchantType = "个体"
        }
//        phoneLabel.text = "\(dict["name"]as? String ?? "")（\(merchantType)）\(dict["shortName"]as? String ?? "")"
        phoneLabel.text = "\(dict["name"]as? String ?? "")（\(merchantType)）"
        statusLabel.text = dict["status"]as? String ?? ""
    }
    @objc func queryAction() {
        if self.queryBlock != nil{
            self.queryBlock!()
        }
    }
}
extension AuthenPendingCheckingCell{
    func initUI() {
        contentView.addSubview(whiteView)
        whiteView.addSubview(mercPhoneLabel)
        whiteView.addSubview(queryButton)
        whiteView.addSubview(arrowImgView)
        whiteView.addSubview(timeLabel)
        whiteView.addSubview(statusLabel)
        whiteView.addSubview(lineView)
        whiteView.addSubview(phoneLabel)
        
        setConstrait()
    }
    func setConstrait(){
        whiteView.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualToSuperview()
            make.top.equalTo(kFitWidth(10))
            make.width.equalTo(kFitWidth(343))
            make.bottom.equalToSuperview()
        }
        mercPhoneLabel.snp.makeConstraints { make in
            make.left.top.equalTo(kFitWidth(12))
        }
        arrowImgView.snp.makeConstraints { make in
            make.right.equalTo(kFitWidth(-12))
            make.centerY.lessThanOrEqualTo(mercPhoneLabel)
            make.width.height.equalTo(kFitWidth(20))
        }
        queryButton.snp.makeConstraints { make in
            make.right.equalTo(arrowImgView.snp.left).offset(kFitWidth(-5))
            make.centerY.lessThanOrEqualTo(arrowImgView)
        }
        timeLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(14))
            make.top.equalTo(kFitWidth(42))
            make.height.equalTo(kFitWidth(17))
        }
        statusLabel.snp.makeConstraints { make in
            make.right.equalTo(kFitWidth(-26))
            make.bottom.equalToSuperview()
            make.height.equalTo(kFitWidth(32))
        }
        lineView.snp.makeConstraints { make in
            make.left.width.equalToSuperview()
            make.height.equalTo(kFitWidth(0.4))
            make.bottom.equalTo(kFitWidth(-32))
        }
        phoneLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(12))
            make.height.equalTo(kFitWidth(32))
            make.bottom.equalToSuperview()
        }
    }
}
